<?php
session_start();

 if ($_SESSION['ADMIN'] == '0') {
 
header("Location: /OLMS/");
}




function mysql_insert($table, $inserts) {
    $values = array_map('mysql_real_escape_string', array_values($inserts));
    $keys = array_keys($inserts);
       
    return mysql_query('INSERT INTO `'.$table.'` (`'.implode('`,`', $keys).'`) VALUES (\''.implode('\',\'', $values).'\')');
}

if (isset($_GET['Update'])) {
$message=$_GET['notice'];
mysql_query("update notices set notice='$message'");
}
?>

<h2> MESSAGES </h2><br>
<?php
$sql = mysql_query("select * from notices");
$row = mysql_fetch_array($sql);
$mess = $row['notice'];

echo "<form method='get'><textarea rows='3' cols='20' name='notice'>$mess</textarea><br><input type='submit' value='Update' name='Update'/></form>";
?>
<?php

// Check if he wants to register:
if (isset($_POST['username'])) {



$uname = $_POST['username'];
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$admin = $_POST['admin'];
$password = $_POST['password'];



	
	mysql_insert('users', array(
    'fname' => $fname,
    'uname' => $uname,
    'lname' => $lname,
	'priv' => $admin,
	'passwd' => md5($password),
));
	

}

?>

<html>
	<head>
		<title>Register</title>
	</head>
	<body>
		<form action="#" method="post">
			<table width="75%" border="1" align="center" cellpadding="3" cellspacing="1">
				<tr>
					<td width="100%"><h5>Registration</h5></td>
				</tr>
				<tr>
					<td width="100%"><label>Desired Username: <input type="text" name="username" size="25" /></label></td>
				</tr>
				<tr>
					<td width="100%"><label>First Name: <input type="text" name="firstname" size="25" value=""></label></td>
				</tr>
				<tr>
					<td width="100%"><label>Last Name: <input type="text" name="lastname" size="25" value=""></label></td>
				</tr>
				<tr>
					<td width="100%"><label>Password: <input type="password" name="password" size="25" value=""></label></td>
				</tr>
				<tr>
					<td width="100%"><label>Verify Password: <input type="password" name="password2" size="25" value=""></label></td>
				
				</tr>
				<tr>
					<td width="100%"><label>Admin? <input type=
					"checkbox" name="admin" value="5"/></label></td>
					
				</tr>
				<tr>
					<td width="100%"><input type="submit" value="Register!"></td>
				</tr>
			</table>
		</form>
	</body>
</html>
